require 'socket'
require 'uri'
require 'net/http'
require 'rexml/document'

include Socket::Constants

QUERY_TEMPLATE = <<EOF
 <requestnavdata>
  <reqparameters>
    <fpsv>30</fpsv>
    <iamsv>101</iamsv>
    <nc12>313911855841</nc12>
    <setnc12>907310010777</setnc12>
    <uid>0</uid>
  </reqparameters>
  <nodeid>385875968</nodeid>
  <serviceid>1</serviceid>
  <numelem>32</numelem>
</requestnavdata>
EOF

node = ARGV[0] ? ARGV[0] : "0" 
msg = QUERY_TEMPLATE
#msg = QUERY_TEMPLATE.gsub(/nodeid_templ/, node)
url = URI.join("http://192.168.2.4", "/")
http = Net::HTTP.new("192.168.2.4", 8081)
res = http.post(url.request_uri, msg)

doc = REXML::Document.new(res.body)
if doc.root.name =~ /contentdataset/
  doc.root.elements.each("/contentdataset/contentdata") do |el|
    name = nodeid = nil
    el.elements.each("name") {|e| name = e.text.to_s}
    el.elements.each("nodeid") {|e| nodeid = e.text.to_i}
    puts "#{name} - #{nodeid}"
  end
end
